﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiArte.Data.Catalog
{
    public class ProductAttributeDal : BaseDal
    {
        /// <summary>
        /// Deletes all product\attribute relations
        /// </summary>
        public void DeleteAll()
        {
            using (var command = new Npgsql.NpgsqlCommand("DELETE FROM product_attribute"))
                PerformCommand(command);
        }

        /// <summary>
        /// Inserts a product\attribute relation
        /// </summary>
        /// <param name="productId">The product id</param>
        /// <param name="attributeId">The attribute id</param>
        public void Insert(int productId, int attributeId)
        {
            using (var command = new Npgsql.NpgsqlCommand("INSERT INTO product_attribute(product_attribute_id, product_id, attribute_id) VALUES " +
                "(nextval('product_attribute_id_sequence'), :product_id, :attribute_id)"))
            {
                command.Parameters.AddWithValue("product_id", productId);
                command.Parameters.AddWithValue("attribute_id", attributeId);

                PerformCommand(command);
            }
        }

    }
}
